﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Team4Mock.Entity;
namespace Team4Mock.UserControl.Address
{
    public partial class ListAddress : System.Web.UI.UserControl
    {
        AddressEntity ae = new AddressEntity();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                gvAddress.DataSource = ae.Getdata();
                gvAddress.DataBind();
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            if (txtpostcode.Text == "" && txtStreet.Text == "" && txtTown.Text == "")
            {
                tb.Text = "Input Post code or Street or Town";
            }
            else
            {

                if (txtpostcode.Text != "")
                {
                    ae.postcode = txtpostcode.Text;
                    ae.county = "";
                    ae.town = "";
                    gvAddress.DataSource = ae.Search(1, ae);
                    gvAddress.DataBind();
                }
                if (txtStreet.Text != "")
                {
                    ae.postcode = "";
                    ae.county = txtStreet.Text;
                    ae.town = "";
                    gvAddress.DataSource = ae.Search(2, ae);
                    gvAddress.DataBind();
                }
                if (txtTown.Text != "")
                {
                    ae.postcode = "";
                    ae.county = "";
                    ae.town = txtTown.Text;
                    gvAddress.DataSource = ae.Search(3, ae);
                    gvAddress.DataBind();
                }

            }
        }

        protected void btnNone_Click(object sender, EventArgs e)
        {
            gvAddress.DataSource = ae.Getdata();
            gvAddress.DataBind();
        }

        protected void btnClear_Click(object sender, EventArgs e)
        {
            txtpostcode.Text = "";
            txtTown.Text = "";
            txtStreet.Text = "";
            txtpostcode.Focus();
        }
    }
}